<?php
class Tourism_goods_profit_model extends BZ_Model
{
    protected $table = 'tourism_goods_profit';

     /**
     * 批量插入
     * @param unknown $postData
     * @param unknown $id
     */
    public function add($postData, $id)
    {
        $data = array();
        foreach ($postData['amount'] as $key=>$value) {
            if ($value > 0) {
                $data[] = array(
                        'status'    => $postData['status'],
                        'goods_attr_id'  => $id,
                        'amount'    => trim($value),
                        'uid'       => trim($postData['uid'][$key]),
                        'bit_trade' => trim($postData['type_id'][$key]),
                );
            }
        }
        return $this->db->insert_batch($this->table, $data);
    }

    public function findByArray($postData)
    {
        if (empty($postData)){
            return false;
        }
        $this->db->select('*');
        $this->db->from($this->table);
        if (!empty($postData['goods_attr_id'])){
            $this->db->where('goods_attr_id', $postData['goods_attr_id']);
        }
        if (!empty($postData['status'])){
            $this->db->where('status', $postData['status']);
        }

        $result = $this->db->get();
        if ($result->num_rows() > 0) {
            return $result;
        }
        return false;
    }
}